package oj0529.oj0529_01;

import java.util.Scanner;

public class Main {
    private static int[][] edge;
    private static boolean[] visited;
    private static int n;


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int m = sc.nextInt();

        edge = new int[n][n];
        visited = new boolean[n];

        for (int i = 0; i < m; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            edge[x][y] = 1;
            edge[y][x] = 1;
        }

        DFS(0);
        sc.close();
    }

    private static void DFS(int x) {
        visited[x] = true;
        System.out.print(x + ",");
        for (int y = 0; y < n; y++) {
            if (edge[x][y] == 1 && visited[y] == false) {
                DFS(y);
            }
        }
    }
}
